package com.framework.file.api;

import com.framework.common.domain.ResultData;
import com.framework.file.model.SysFile;
import feign.Response;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@FeignClient(name = "file-server",fallback=FileServiceFallback.class)
public interface FileService {
    @PostMapping(value = "/file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResultData upload(@RequestPart(value = "file") MultipartFile file, @RequestParam String module, @RequestParam(required = false) String form, @RequestParam String part,
                      @RequestParam String createrId, @RequestParam String createrComId);

    @GetMapping(value = "/file/download", consumes = MediaType.APPLICATION_JSON_VALUE)
    Response download(@ApiParam("文件id") @RequestParam(value = "id") String id);

    @PostMapping(value = "/file/previewBatch")
    ResultData<Map<String, String>> previewBatch(@ApiParam("文件ids") @RequestParam(value = "idsList") List<String> idsList);

    @GetMapping(value = "/file/getFileById")
    ResultData<SysFile> getFileById(@ApiParam("文件id") @RequestParam String id);

    @PostMapping(value = "/file/apiUploadAndUpdate")
    ResultData apiUploadAndUpdate(@RequestBody SysFile fastDFSFile,@RequestParam String oldFileId);

    @PostMapping(value = "/file/apiUpdateFile")
    ResultData apiUpdateFile(@RequestBody SysFile fastDFSFile);

    @PostMapping(value = "/file/getFiles")
    ResultData<Map<String, List<SysFile>>> getFiles(@ApiParam("所属模块") @RequestParam String module,
                                                    @ApiParam("所属表单") @RequestParam String form,
                                                    @RequestParam(required = false) String part);

    @PostMapping(value = "/file/getFilesByForm")
    ResultData<Map<String, List<SysFile>>> getFiles(@ApiParam("所属表单") @RequestParam String form);

    @PostMapping(value = "/file/deleteFileByForm")
    ResultData deleteFilesByForm(@ApiParam("业务id") @RequestParam String form, @ApiParam("组") @RequestParam String part);
}
